import vue from "@vitejs/plugin-vue";
import path from "path";
// https://vitejs.dev/config/
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
// 引入 Mock 配置
import { viteMockServe } from "vite-plugin-mock";
export default ({ command }) => {
  return {
    // base: "./",scale-order
    base: "/scale-order/",
    plugins: [
      vue(),
      // 配置 icon
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        symbolId: "icon-[dir]-[name]",
      }),
      // 配置mock服务
      viteMockServe({
        mockPath: "./src/mock", // 文件位置
        // 保证开发阶段可以使用 Mock 接口， 会自动开启 mock 服务（ npm run mock）
        localEnabled: command === "serve",
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"), // 相对路径别名配置 @ 代替 src
      },
    },
    css: {
      preprocessorOptions: {
        // 全局注册 SCSS
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    server: {
      host: "0.0.0.0",
    },
  };
};
